//
//  CLIconVCCell.m
//  ZYSliderViewController
//
//  Created by yoyo on 2021/3/8.
//  Copyright © 2021 CL. All rights reserved.
//

#import "CLIconVCCell.h"
#import "JGCollectionViewFlowLayout.h"
#import "JGCollectionViewCell.h"

@interface CLIconVCCell ()  <UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *CollectionView;

@end
static NSString * const JGCollectionViewCellId = @"JGCollectionViewCellId";


@implementation CLIconVCCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.CollectionView];

}

- (UICollectionView *)CollectionView {
    if (!_CollectionView) {
        JGCollectionViewFlowLayout *layout = [[JGCollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(300, 127);
        layout.minimumLineSpacing = 26;// 水平
        layout.minimumInteritemSpacing = 13;// 垂直方向
        CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 127);
        NSLog(@"widht:%f, height:%f", self.frame.size.width, self.frame.size.height);
        _CollectionView = [[UICollectionView alloc] initWithFrame:rect collectionViewLayout:layout];
        _CollectionView.backgroundColor = [UIColor clearColor];
        _CollectionView.delegate = self;
        _CollectionView.dataSource = self;
        _CollectionView.showsHorizontalScrollIndicator = NO;
        //注册重用
        [_CollectionView registerClass:[JGCollectionViewCell class] forCellWithReuseIdentifier:JGCollectionViewCellId];
        
    }
    return _CollectionView;
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    JGCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:JGCollectionViewCellId forIndexPath:indexPath];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"%ld - %ld", indexPath.section, indexPath.row);
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
